let userAgent = require("user-agent");
function getExtraData() {
  return {
    title: document.title,
    url: location.href,
    referrer: document.referrer,
    userAgent: userAgent,
  };
}
class SendTracker {
  constructor() {
    this.url = "http://thirdparty.com/monitor/log"; // 第三方服务地址
    this.xhr = new XMLHttpRequest();
  }
  send(data = {}) {
    const log = { ...getExtraData(), ...data };
    this.xhr.open("POST", this.url, true);
    this.xhr.setRequestHeader("Content-Type", "application/json");
    this.xhr.send(JSON.stringify(log));
  }
}

export default new SendTracker();
